10 - OAuth (4) Resource owner password credentials grant

Client直接將使用者的 credentials 透過 POST method 送到 Authorization server,params 包含
POST /token
Content-Type: application/x-www-form-urlencoded
{
  grant_type: password,
  scope: xxx,
  resource: xxx,
  username: xxx,
  password:xxx
}
grant_type: 這裡使用 "password" 代表我們要使用 OAuth Resource owner password credentials grantscope: 代表這個請求所想要取得授權的內容,譬如 get:dataresource: 在 Authorization server 所登記的 Resource server 的 IDusername & password: 使用者的 credentials會發現這裡沒有送出 client_id 到 Authorization server,那是因為這時候的 Client 已經直接取得使用者的 credentials,意義上可以說是使用者已經直接授權給 Client 了,因此不需要特別檢查這個 Client 是否為有註冊的 Client
Authorization server 收到 Client 送來的使用者 credentials、驗證完之後,就會回傳 response 給 Client,當中包含 access token 和 refresh token 等資訊。
{
  access_token: xxx,
  token_type: xxx,
  expired_in: xxx,
  refresh_token: xxx
}
access_token: Client 可以用來向 Resource server 發送請求token_type: token 的類型,譬如 "Bearer"expired_in: token 的續存時間refresh_token: 在 access_token 到期之後,Client 可以拿 refresh_token 向 Authorization server 取得新的 access_token
由於這裡是透過 api 的 request/response 來傳遞資訊,因此相較於直接把 access token 放在 redirect url 當中還要來得安全許多